_init: function(source, size) {
this._source = source;
+ this._size = size;
this.actor = new Shell.GenericContainer();
this.actor.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
this._source.connect('count-updated', Lang.bind(this, this._updateCount));
this._updateCount();
+
+ this._source.connect('icon-updated', Lang.bind(this, this._updateIcon));
+ this._updateIcon();
},
setIcon: function(icon) {
this._iconBin.child = icon;
+ this._iconSet = true;
},
_getPreferredWidth: function (actor, forHeight, alloc) {
this._counterBin.allocate(childBox, flags);
},
+ _updateIcon: function() {
+ if (this._actorDestroyed)
+ return;
+
+ if (!this._iconSet)
+ this._iconBin.child = this._source.createIcon(this._size);
+ },
+
_updateCount: function() {
if (this._actorDestroyed)
return;
this._counterBin.visible = this._source.countVisible;
this._counterLabel.set_text(this._source.count.toString());
- },
+ }
});
const Source = new Lang.Class({
icon_size: size });
},
- _ensureMainIcon: function(icon) {
+ _ensureMainIcon: function() {
if (this._mainIcon)
- return false;
-
- if (!icon)
- icon = this.createIcon(this.ICON_SIZE);
+ return;
this._mainIcon = new SourceActor(this, this.ICON_SIZE);
- this._mainIcon.setIcon(icon);
- return true;
+ return;
},
// Unlike createIcon, this always returns the same actor;
return false;
},
+ iconUpdated: function() {
+ this.emit('icon-updated');
+ },
+
//// Protected methods ////
_setSummaryIcon: function(icon) {
- if (!this._ensureMainIcon(icon))
- this._mainIcon.setIcon(icon);
+ this._ensureMainIcon();
+ this._mainIcon.setIcon(icon);
+ this.iconUpdated();
},
open: function(notification) {
processNotification: function(notification, gicon) {
if (gicon)
this._gicon = gicon;
- this._setSummaryIcon(this.createIcon(this.ICON_SIZE));
+ if (!this.trayIcon)
+ this.iconUpdated();
let tracker = Shell.WindowTracker.get_default();
if (notification.resident && this.app && tracker.focus_app == this.app)
// notification-based icons (ie, not a trayicon) or if it was unset before
if (!this.trayIcon) {
this.useNotificationIcon = false;
- this._setSummaryIcon(this.createIcon(this.ICON_SIZE));
+ this.iconUpdated();
}
},
_makeNotificationSource: function(source) {
let box = new St.BoxLayout({ style_class: 'screen-shield-notification-source' });
- let iconClone = source.createIcon(SUMMARY_ICON_SIZE);
let sourceActor = new MessageTray.SourceActor(source, SUMMARY_ICON_SIZE);
- sourceActor.setIcon(iconClone);
box.add(sourceActor.actor, { y_fill: true });
let textBox = new St.BoxLayout({ vertical: true });